package com.su.sweet.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class DbUtil {
    public static void executeSqlFile(String filePath) throws Exception {
        String url = "jdbc:mysql://localhost:13306/sweet";
        String user = "root";
        String password = "123456";

        try (Connection conn = DriverManager.getConnection(url, user, password);
             Statement stmt = conn.createStatement();
             BufferedReader reader = new BufferedReader(new FileReader(filePath))) {

            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }

            String sql = sb.toString();
            stmt.execute(sql);
            System.out.println("SQL executed successfully");
        }
    }
}